* ******************************************************************** *
* ******************************************************************** *
*                                                                      *
*               FDI PAPER   		                               *
*               MASTER_MERGE_CLEAN.DO                                  *
*                                                                      *
* ******************************************************************** *
* ******************************************************************** *

PURPOSE:
The first section of the .do file sets up the directory structure so that multiple users can easily access datasets and related .do files. It then calls a series of data cleaning scripts, each responsible for cleaning raw data from different sources and preparing them for merging.

The final section merges all the cleaned datasets into a single master dataset (masterV2.csv), which is ready for analysis.

How to change user: 

The first section of the .do file is designed to easily switch between users. Each user needs to update the global path variable, which automatically adjusts all directory references throughout the project.

To set up a new user:

Assign a user number:
		* Edit lines 44–46 to assign yourself a unique user number.

Define your path
		* Add your file paths under the corresponding user number in the global path section (lines 62–72).

Activate your user profile
		* Update the user switch on line 49 to match your assigned user number.

Once the user switch is updated, run the master_merge_clean.do file. This will clean all raw datasets, merge them, and output the final masterV2.csv file for analysis.


PURPOSE OF EACH .DO FILE CALLED: 

CLEANING .DO FILES:

* Original/raw_master.do:
	Input: finaldatset30_COPY.xlsx
	Input Source: 
	Output: master.dta
	Core functions of the code: rename variable names iso_code, country and year
 
* Armed Conflict/raw_armedconflict.do	
	Input: 
		* UcdpPrioConflict_v25_1.dta
		* country_codes_ref.csv
	Input Source: 
	Output: 
		* armed_conflict_cleaned.dta
		* country_codes_ref.dta
	Core functions of the code: Clean up location string, drop missing location, and clean country names
 
* Corruption Index/raw_v2.do	
	Input: CPI from year 2000-2011
	Input Source: 
	Output: corruption_index_final.dta
	Core functions of the code: clean and append annual CPI data from year 2000-2011

* Economic Freedom Indicator/raw.do
	Input: 
		* heritage-index.csv
		* country_codes_ref.dta
	Input Source: 
	Output: heritage_index_cleaned.dta
	Core functions of the code: Clean country names and merge with country codes

* Global Competitiveness/raw.do
	Input: WEF_GCI.csv
	Input Source: 
	Output: WEF_GCI.csv
	Core functions of the code: No changes

* Government Stability Measures/raw_gov_stab.do
	Input: wgidataset.dta
	Input Source: 
	Output: gov_stab_measures.dta
	Core functions of the code: Reshape the data, and clean variable names for consistency across all datasets

* Trade Open/trade_open_raw.do
	Input: trade_open_raw.csv
	Input Source: 
	Output: trade_open.dta
	Core functions of the code: Reshape data from wide to long

* Transport Infra/raw.do
	Input: transport_infra.csv
	Input Source: 
	Output: transport_infra.dta
	Core functions of the code:  Reshape data from wide to long

MERGE .DO FILE:

* Merge Code/master_merge.do
	Inputs:
		* master.dta
		* armed_conflict_cleaned.dta
 		* corruption_index_final.dta
		* heritage_index_cleaned.dta
		* gov_stab_measures.dta
		* trade_open.dta
		* transport_infra.dta
	Output: 
		* masterV2.dta
		* masterV2.csv
	Core functions of the code: 
		* Created intensity index for armed conflicts
		* Merges the data with other indicators based on country_code, iso, and year. 



